package com.alibaba.service;

import com.alibaba.bean.TopFace;
import com.alibaba.bean.TopFaceResult;
import com.alibaba.mapper.TopFaceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TopFaceService {

    @Autowired
    private TopFaceMapper topFaceMapper;

    public TopFaceResult topValue(int userId) {
        TopFaceResult tfr = new TopFaceResult();
        TopFace tfa = new TopFace();
        tfr.setResult(false);
        try{
            if(userId == topFaceMapper.findTopValue()) {
                float fv1 = topFaceMapper.findPersonalTopValue(userId);
                tfa.setFaceVal(fv1);
                tfa.setUserId(userId);
                tfa.setuName(topFaceMapper.name(userId));
                tfa.setAva(topFaceMapper.ava(userId));
                tfr.setResult(true);
                tfr.setErrmsg("搜索成功");
                tfr.setData(tfa);
            } else {
                float fv2 = topFaceMapper.findPersonalTopValue(topFaceMapper.findTopValue());
                tfr.setErrmsg("当前不是最高");
                tfa.setFaceVal(fv2);
                tfa.setuName(topFaceMapper.name(topFaceMapper.findTopValue()));
                tfa.setAva(topFaceMapper.ava(topFaceMapper.findTopValue()));
                tfa.setUserId(topFaceMapper.findTopValue());
                tfr.setData(tfa);
            }
        } catch (Exception e) {
            tfr.setErrmsg(e.getMessage());
            e.printStackTrace();
        }
        /*System.out.println(topFaceMapper.findRecords(userId));
        System.out.println(topFaceMapper.name(userId));
        System.out.println(topFaceMapper.ava(userId));
        System.out.println(tfa.getUserId());*/
        return tfr;

    }

}
